package com.tgy.demo;

import com.tgy.demo.utils.JdbcUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/***
 * @ClassName: TestInsert
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 21:45 2021/11/29
 * @version : V1.0
 */
public class TestInsert {
    public static void main(String[] args)  {

        //SQL注入问题
        //testLogin.login("lisi' OR '1=1","123456");

        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            //得到连接
            connection = JdbcUtils.getConnection();
            //得到执行器
            statement = connection.createStatement();
            //编写sql
            String insertSql = "insert into users(`name`,`password`,`email`,`birthday`) values ('aaa','daqsd','ewrwe','2110-12-01')";
            String deleteSql = "delete from users where id = 5";
            String updateSql = "update users set name = '啊哈哈哈' where id = 5";
            String querySql = "select * from users ";

            int i1 = statement.executeUpdate(insertSql);
            int i2 = statement.executeUpdate(updateSql);

            System.out.println(i1);
            System.out.println(i2);

            resultSet = statement.executeQuery(querySql);
            while (resultSet.next()){
                System.out.println(resultSet.getString("name"));
            }
            int i3 = statement.executeUpdate(deleteSql);
            System.out.println(i3);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            JdbcUtils.release(connection,statement,resultSet);
        }

    }
}
